package com.ruoyi.accountant.mapper;

import com.ruoyi.accountant.domain.ReasonDetail;
import com.ruoyi.accountant.domain.other.CashFlowItem;
import com.ruoyi.accountant.domain.other.Cashflow;
import com.ruoyi.accountant.domain.other.ProfitLossReport;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface ReportMapper {
    @Select("select t.month, t.money,tr.rname,t.tax from (select month(proof_date) as month, sum(main_currency_money) as money, of_reason, sum(tax) as tax\n" +
            "    from t_transaction_detail as t where of_reason = #{ofReason} and deleted = 0 group by of_reason, month(proof_date)) as t\n" +
            "        left outer join t_reason tr on tr.rid = t.of_reason where tr.rtype = #{type} ;")
    List<ProfitLossReport> findByTypeAndReason(@Param("type") String type, @Param("ofReason") Long ofReason);

    @Select("select t.month, t.money,tr.rname,t.tax from (select month(proof_date) as month, sum(main_currency_money) as money, of_reason, sum(tax) as tax\n" +
            "    from t_transaction_detail as t where of_reason = #{ofReason} and deleted = 0 group by of_reason, month(proof_date)) as t\n" +
            "        left outer join t_reason tr on tr.rid = t.of_reason where tr.rtype = #{type} ;")
    List<Object[]> findByTypeAndReasonS(@Param("type") String type, @Param("ofReason") Long ofReason);

    @Select("select money, cn_name,of_account,a.aname  from\n" +
            "(select sum(money) as money, of_currency,of_account from t_transaction_detail\n" +
            "where \n" +
            "dtype = #{type} and of_company=#{ofCompany} and deleted = 0 and proof_date between #{start} and  #{end}\n" +
            "group by of_currency) as t\n" +
            "left outer join t_currency as c on t.of_currency = c.cid\n" +
            "left outer join t_account as a on t.of_account = a.aid;")
    List<CashFlowItem> findCashFlowByType(@Param("type") String type,@Param("start") Date start,@Param("end") Date end,@Param("ofCompany") Long ofCompany);

}
